package com.example.demolearn_2.activity;

import android.content.Intent;
import android.os.Bundle;
import android.view.animation.AlphaAnimation;
import android.view.animation.Animation;
import android.view.animation.AnimationSet;
import android.view.animation.RotateAnimation;
import android.view.animation.ScaleAnimation;
import android.widget.RelativeLayout;

import androidx.appcompat.app.AppCompatActivity;

import com.example.demolearn_2.R;

public class SplashActivity extends AppCompatActivity {


    private RelativeLayout mRl_splash_root;

    public static final String START_MAIN = "start_main";

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_splash);

        mRl_splash_root  = findViewById(R.id.rl_splash_root);

        AlphaAnimation aa = new AlphaAnimation(0,1);
//        aa.setDuration(500);//持续播放时间
        aa.setFillAfter(true);

        ScaleAnimation sa = new ScaleAnimation(0,1,0,1, ScaleAnimation.RELATIVE_TO_SELF,0.5f, ScaleAnimation.RELATIVE_TO_SELF,0.5f);
//        sa.setDuration(500);
        sa.setFillAfter(true);

        RotateAnimation ra = new RotateAnimation(0,360, RotateAnimation.RELATIVE_TO_SELF,0.5f, RotateAnimation.RELATIVE_TO_SELF,0.5f);
//        ra.setDuration(500);
        ra.setFillAfter(true);

        AnimationSet set = new AnimationSet(false);

        set.addAnimation(ra);
        set.addAnimation(ra);
        set.addAnimation(sa);
        set.setDuration(2000);//实际播放时间

        mRl_splash_root.startAnimation(set);

        set.setAnimationListener(new Animation.AnimationListener() {
            @Override
            public void onAnimationStart(Animation animation) {

            }

            @Override
            public void onAnimationEnd(Animation animation) {
//                boolean isStartMain= CacheUtils.getBoolean(SplashActivity.this, START_MAIN);
//                Intent intent;
//                if (isStartMain){
//                    intent =new Intent(SplashActivity.this,MainActivity.class);
//                }else{
//                    //如果没有进入过主页面，进入引导页面
//                    intent = new Intent(SplashActivity.this, GuideActivity.class);
//                }
//                startActivity(intent);
                Intent intent;
                intent = new Intent(SplashActivity.this, GuideActivity.class);
                startActivity(intent);

                //关闭Splash页面
                finish();
            }

            @Override
            public void onAnimationRepeat(Animation animation) {

            }
        });
    }
}
